from flask import Blueprint, render_template
from flask_login import login_required  # 保护路由，需登录才能访问
from app.models import User, Movie  # 如需传递数据可保留，无需则删除

main_bp = Blueprint("main", __name__, url_prefix="/")

# ========== 原有路由（保留） ==========
@main_bp.route("/")
@main_bp.route("/index")
@main_bp.route("/home")
@login_required
def index():
    user = User.query.first()
    movies = Movie.query.order_by(Movie.id).all()
    return render_template("page/index.html", user=user, movies=movies)

@main_bp.route("/dashboard")
@login_required
def dashboard():
    return render_template("page/dashboard.html")

@main_bp.route("/settings")
@login_required
def settings():
    user = User.query.first()
    return render_template("page/settings.html", user=user)

@main_bp.route("/users")
@login_required
def users():
    return render_template("page/users.html")

# ========== 新增：产品管理路由 ==========
@main_bp.route("/products")
@login_required
def products():
    # 可根据需求传递产品数据到模板，示例：
    # products = Product.query.all()
    # return render_template("page/products.html", products=products)
    return render_template("page/products.html")  # 先返回空模板

# ========== 新增：订单管理路由 ==========
@main_bp.route("/orders")
@login_required
def orders():
    # 可根据需求传递订单数据到模板，示例：
    # orders = Order.query.all()
    # return render_template("page/orders.html", orders=orders)
    return render_template("page/orders.html")  # 先返回空模板